package com.tiheima.service.impl;

import com.tiheima.mapper.EmpLogMapper;
import com.tiheima.model.entity.EmpLog;
import com.tiheima.service.EmpLogService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class EmpLogServiceImpl implements EmpLogService {

    private final EmpLogMapper empLogMapper;

    public EmpLogServiceImpl(EmpLogMapper empLogMapper) {
        this.empLogMapper = empLogMapper;
    }

    //使用异步的方式
    @Async
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void insertLog(EmpLog empLog) {
        System.out.println("日志当前线程："+Thread.currentThread().getName()+"--------------------");
        empLogMapper.insert(empLog);
    }
}
